<%--
  Created by IntelliJ IDEA.
  User: ddd
  Date: 2018/4/16
  Time: 21:18
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>新增科目信息</title>
    <link href="${pageContext.request.contextPath}/static/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css"
          href="${pageContext.request.contextPath}/static/css/bootstrap-datetimepicker.min.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/css/admin.css">
</head>
<body>
<div style="padding: 15px;">
    <form id="fo" class="bs-example bs-example-form" role="form" method='post' enctype="multipart/form-data">
        <div class="input-group">
            <span class="input-group-addon">分类名称</span>
            <input type="text" name='name' class="form-control" placeholder="请输入习题分类名称">
        </div>
        <br>
        <div class="input-group">
            <span class="input-group-addon">藏语分类名称</span>
            <input type="text" name='zname' class="form-control" placeholder="请输入藏语习题分类名称">
        </div>
        <br>
        <div class="input-group">
            <span class="input-group-addon">排序号码</span>
            <input type="number" name='px' class="form-control" placeholder="请输入序列号">
        </div>
        <br>
        <div class="input-group">
            <span class="input-group-addon">当前状态</span>
            <select name="status" class="form-control">
                <option value="1">启用</option>
                <option value="0">禁用</option>
            </select>
        </div>
        <br>
        <div class="input-group">
            <span class="input-group-addon">分类图标</span>
            <input type="file" name='courseImg' class="form-control" placeholder="请选择图标文件">
            <input type="hidden" name="coid" value=''>
        </div>
        <br>
        <button type="button" class="btn btn-primary btn-lg btn-block" onclick='ValidForm()'>提交保存</button>
    </form>
</div>
</body>
<script src="${pageContext.request.contextPath}/static/js/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/static/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/static/layer/layer.js"></script>
<script type="text/javascript">
    function ValidForm() {
        var name = $('input[name=name]').val(),
            zname = $('input[name=zname]').val(),
            px = $('input[name=px]').val(),
            file = $('input[name=courseImg]').val(),
            key = $('input[name=coid]').val();
        if (!name) {
            layer.msg('请输入习题分类名称', {icon: 2, time: 1000});
            $('input[name=name]').focus();
            return false;
        }
        if (!px) {
            layer.msg('请输入序列号', {icon: 2, time: 1000});
            $('input[name=px]').focus();
            return false;
        }
        if (!file) {
            layer.msg('请选择图标文件', {icon: 2, time: 1000});
            $('input[name=courseImg]').focus();
            return false;
        }
        if (!key) {
            layer.msg('参数错误', {icon: 2, time: 1000});
            setTimeout(function () {
                top.location.reload();
            }, 1000);
            return false;
        }

        var formData = new FormData($("#fo")[0]);
        $.ajax({
            async: false,
            cache: false,
            type: "post",
            data: formData,
            url: '/exertype',
            dataType: 'json',
            contentType: false, //必须
            processData: false, //必须
            success: function (json) {
                if (json.status == "success") {
                    layer.msg('添加成功', {icon: 1, time: 1000});
                    setTimeout(function () {
                        parent.location.reload();
                    }, 1000);
                }
            },
            error: function () {
                layer.msg('服务器繁忙，请刷新页面后重试', {icon: 5, time: 1000});
            }
        });
    }


</script>
</html>
